package com.ruoyi.system.controller.repair;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.db.basic.BasicVehicles;
import com.ruoyi.system.domain.db.repair.VehicleRepair;
import com.ruoyi.system.domain.vo.PageInfo;
import com.ruoyi.system.domain.vo.repair.RepairDriverVo;
import com.ruoyi.system.utils.MyPageUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IVehicleRepairService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 报修申请Controller
 * 
 * @author ruoyi
 * @date 2023-07-31
 */
@RestController
@RequestMapping("/repair/driver")
public class VehicleRepairController extends BaseController
{
    @Autowired
    private IVehicleRepairService vehicleRepairService;

    /**
     * 查询报修申请列表
     */
    @PreAuthorize("@ss.hasPermi('repair:driver:list')")
    @GetMapping("/list")
    public PageInfo<RepairDriverVo> list(VehicleRepair vehicleRepair)
    {
        // startPage();
        List<RepairDriverVo> repairDriverVos = vehicleRepairService.selectVehicleRepairList(vehicleRepair);
        return MyPageUtils.startPage(repairDriverVos);
    }

    /**
     * 查看是否自己拥有汽车
     * 有的话返回
     */
    @PreAuthorize("@ss.hasPermi('repair:driver:hasCar')")
    @GetMapping("/hasCar")
    public BasicVehicles list()
    {
        return vehicleRepairService.hasVehicle();
    }

    /**
     * 导出报修申请列表
     */
    @PreAuthorize("@ss.hasPermi('repair:driver:export')")
    @Log(title = "报修申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleRepair vehicleRepair)
    {
        List<RepairDriverVo> repairDriverVos = vehicleRepairService.selectVehicleRepairList(vehicleRepair);
        ExcelUtil<RepairDriverVo> util = new ExcelUtil<RepairDriverVo>(RepairDriverVo.class);
        util.exportExcel(response, repairDriverVos, "报修申请数据");
    }

    /**
     * 获取报修申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('repair:driver:query')")
    @GetMapping(value = "/{repairId}")
    public AjaxResult getInfo(@PathVariable("repairId") Long repairId)
    {
        return success(vehicleRepairService.selectVehicleRepairByRepairId(repairId));
    }

    /**
     * 新增报修申请
     */
    @PreAuthorize("@ss.hasPermi('repair:driver:add')")
    @Log(title = "报修申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleRepair vehicleRepair)
    {

        return toAjax(vehicleRepairService.insertVehicleRepair(vehicleRepair));
    }

    /**
     * 修改报修申请
     */
    @PreAuthorize("@ss.hasPermi('repair:driver:edit')")
    @Log(title = "报修申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleRepair vehicleRepair)
    {
        return toAjax(vehicleRepairService.updateVehicleRepair(vehicleRepair));
    }

    /**
     * 删除报修申请
     */
    @PreAuthorize("@ss.hasPermi('repair:driver:remove')")
    @Log(title = "报修申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repairIds}")
    public AjaxResult remove(@PathVariable Long[] repairIds)
    {
        return toAjax(vehicleRepairService.deleteVehicleRepairByRepairIds(repairIds));
    }
}
